﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<script>
    var orderId = $.request("orderId");
    var formId = $.request("formId");

    function find_checkbox(success, error) {
        var $gridList = this;
        var checkboxs = $gridList.find("input[type='checkbox']:checked"),
            selectedVals = [];
        if (checkboxs.length) {
            checkboxs.each(function (n, ele) { selectedVals.push(ele.value); });
            success && success(selectedVals);
        } else {
            error && error();
        }
    }

    function valid_checkbox() {
        var args = Array.prototype.slice.call(arguments);
        if (args.length == 1) {
            args.push(function () {
                $.modalAlert("请选择相关的订单项", "success");
            });
        }
        find_checkbox.apply(this, args)
    }

    $(function () {
        $.ajax({
            url: "/OrderFlowManage/ClientOrder/GetTakelookJson",
            data: { orderId: orderId },
            dataType: "json",
            async: false,
            success: function (data) {
                //console.log(JSON.stringify(data))
                var index = 1;
                var $previewTakelookGrid = $('#previewTakelookGrid');
                var html = '',
                    first = '';
                for (var i in data.rows) {
                    var item = data.rows[i];
                    html += '<tr id="tr' + index + '">';
                    html += '<td>';
                    if (first != item.F_No) {
                        html += '<input type="checkbox" value="' + item.F_SiteId + '|' + item.F_SpaceId + '|' + item.F_No + '">';
                    }
                    html += '</td>';
                    html += '<td>';
                    if (first != item.F_No) {
                        html += item.F_No;
                        first = item.F_No;
                    }
                    html += '</td>';
                    html += '<td>';
                    html += item.OrderCustomerName;
                    html += '</td>';
                    html += '<td>';
                    html += item.SiteName + '-' + item.SpaceName;
                    html += '</td>';
                    html += '<td>';
                    html += item.CustomerName || "";
                    html += '</td>';
                    html += '<td>';
                    html += item.CustomerPhone || "";
                    html += '</td>';
                    html += '<td>';
                    html += item.CompanyName || "";
                    html += '</td>';
                    html += '<td>';
                    html += $.map(JSON.parse(item.Times), function (n) { return n.startTime + '至' + n.endTime; }).join('<br >');
                    html += '</td>';
                    html += '<td>';
                    html += $.map(JSON.parse(item.Cars), function (n) { return n.resName + '车牌号：' + n.carName + '司机：' + n.driverName; }).join('<br >');
                    html += '</td>';
                    html += '<td>';
                    html += $.map(JSON.parse(item.Users), function (n) { return n.deptName + ' ' + n.userName; }).join('<br >');
                    html += '</td>';
                    html += '</tr>';
                    index++;
                }
                $previewTakelookGrid.html(html);
            }
        });
    });

    function submitForm() {
        var $previewTakelookGrid = $('#previewTakelookGrid');
        var trs = $previewTakelookGrid.find('tr');

        valid_checkbox.call($previewTakelookGrid, function (cks) {
            if (cks.length) {
                $.submitForm({
                    url: "/OrderFlowManage/ClientOrder/SubmitTakelookForm?keyValue=" + orderId,
                    param: {
                        orderId: orderId,
                        flowFormId: formId,
                        siteIds: cks,
                        no: cks[0].split('|')[2]
                    },
                    success: function () {
                        //$.currentWindow().vm.takkelook.initTakelook();
                        $.currentWindow().$("#btn_takelook").prop("disabled", true);

                        $.loading(false);
                    }
                });
            } else {
                $.modalMsg("一次最多只能申请一个批次的场地申请", "success");
            }
        });
    }
</script>

<form id="form1">
    <div style="margin:0 20px;">
        <table class="table table-condensed table-bordered">
            <thead>
                <tr>
                    <td width="30">序号</td>
                    <td>批次号</td>
                    <td>订单跟进人</td>
                    <td>带看场地</td>
                    <td>客户名称</td>
                    <td>联系电话</td>
                    <td>公司名称</td>
                    <td>带看时间</td>
                    <td>预约车辆</td>
                    <td>预约陪同人员</td>
                </tr>
            </thead>
            <tbody id="previewTakelookGrid"></tbody>
        </table>
    </div>
</form>


